<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>教师课程管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="/css/font.css">
		<link rel="stylesheet" href="/css/xadmin.css">
		<link rel="stylesheet" href="/css/myCustom.css">
	</head>

	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="#">教师管理</a>
				<a><cite>教师课程管理</cite></a>
			</span>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
			 title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>

		<div class="x-body" id="app">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md3">
					<div class="layui-card">
						<xblock>
							院系列表
						</xblock>
						<ul id="majorTree">
							<li><a href="javascript:;" class="allMajor"><i class="layui-icon layui-tree-leaf"></i><cite>全部</cite></a></li>
						</ul>
					</div>
				</div>
				<div class="layui-col-md9">
					<span class="x-right" style="line-height:40px;float:left">共有数据：{{ pageInfo.total }} 条，当前{{ pageInfo.pageNum }} / {{ pageInfo.pages }}页</span>
					<table class="layui-table">
						<thead>
							<tr>
								<th>教师编号</th>
								<th>姓名</th>
								<th width="40">性别</th>
								<th>课程数量</th>
								<th>院系</th>
								<th width="170">操作</th>
						</thead>
						<tbody>
							<tr v-for="teacher in teachers">
                                <td>{{ teacher.teacherNo }}</td>
                                <td>{{ teacher.teacherName }}</td>
                                <td v-if="teacher.teacherSex == 1">女</td>
                                <td v-else-if="teacher.teacherSex == 2">男</td>
                                <td>{{ teacher.courseNum }}</td>
                                <template v-for="schOrg in schOrgs">
                                <td v-if="schOrg.id == teacher.orgId">{{ schOrg.orgName }}</td>
                                </template>
                                <td class="td-manage">
                                    <button class="layui-btn layui-btn layui-btn-sm" onclick="open_courseManager(this)" :data-teacherNo="teacher.teacherNo" :data-teacherName="teacher.teacherName" :data-orgId="teacher.orgId"><i class="layui-icon">&#xe63c;</i>课程管理</button>
                                    <button class="layui-btn layui-btn layui-btn-sm" onclick="open_courseTime(this)" :data-teacherNo="teacher.teacherNo" :data-teacherName="teacher.teacherName"><i class="layui-icon">&#xe637;</i>课表</button>
                                </td>
                            </tr>
						</tbody>
					</table>
					<div class="page" style="margin-top: 10px !important;">
                         <div>
                           <a class="prev pageTxt" href="javascript:void(0)">上一页</a>
                           <a class="first pageTxt" href="javascript:void(0)">首页</a>
                           <template v-for="pageNum in pageInfo.navigatepageNums">
                               <a class="num" href="javascript:void(0)" v-if="pageInfo.pageNum != pageNum" :data="pageNum">{{ pageNum }}</a>
                               <span class="current" v-else :data="pageNum">{{ pageNum }}</span>
                           </template>
                           <a class="last pageTxt" href="javascript:void(0)">尾页</a>
                           <a class="next pageTxt" href="javascript:void(0)">下一页</a>
                         </div>
                   </div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="/js/jquery.min.js"></script>
        <script type="text/javascript" src="/js/xadmin.js"></script>
        <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/js/vue.min.js"></script>
        <script type="text/javascript" src="/js/jquery.form.js"></script>
		<script>
			var vm = new Vue({
	            el : '#app',
	            data : {
	                // 院系列表
	                schOrgs : "",
	                pageInfo:"",
	                teachers: "",
	                // 当前选中的院系id
	                orgId: 0,
	                // 当前选中的院系名称
	                orgName: ""
	            },
	            created : function() {
	                // 获取学校院系列表
	                this.listSchOrgWithTree();
	                // 获取教师列表(0:全部)
	                this.listTeacher(0, 1);
	            },
	            methods : {
	                listSchOrgWithTree : function() {
	                    var vm = this;
	                    $.ajax({
	                        url : "/sys/teacher/course/listSchOrgWithTree",
	                        type : "get",
	                        success : function(result) {
	                            if (result.state) {
	                                var data = result.data;
	                                var schOrgTree = JSON.parse(data.listSchOrgWithTree);
	                                vm.schOrgs = data.listSchOrg;
	                                // 加载tree数据(放在其它地方会容易导致加载不出来tree数据)
	                                layui.use('tree', function() {
	                                    layui.tree({
	                                        elem: '#majorTree', //传入元素选择器
	                                        nodes: schOrgTree,
	                                        click: function(node) {
	                                            // node即为当前点击的节点数据
	                                            if (vm.orgId != node.id) {
	                                                vm.orgId = node.id;
	                                                vm.orgName = node.name;
	                                                vm.listTeacher(vm.orgId, 1);
	                                            }
	                                        }
	                                    });
	                                });
	                            } else {
	                                layui.use(['layer'], function(){
	                                    var layer = layui.layer
	                                    layer.msg(""+result.msg, {icon: 5});
	                                });
	                            }
	                        }
	                    });
	                },
	                listTeacher: function(orgId, pageNum) {
	                    var vm = this;
	                    $.ajax({
	                        url : "/sys/teacher/course/listTeacher",
	                        data:{
	                            orgId: orgId,
	                            pageNum: pageNum
	                        },
	                        type : "get",
	                        success : function(result) {
	                            if (result.state) {
	                                vm.pageInfo = result.data;
	                                vm.teachers = result.data.list;
	                            } else {
	                                layui.use(['layer'], function(){
	                                    var layer = layui.layer
	                                    layer.msg(""+result.msg, {icon: 5});
	                                });
	                            }
	                        }
	                    });
	                }
	            }
	        });

			$(function() {
                // 首次加载tree数据时,默认选中"全部"
                $("#majorTree li:first").addClass("selectColor");
            })

            // 对选中的当前树节点加背景颜色
            $("body").on("mousedown", ".layui-tree li a", function() {
                $(".layui-tree li, li a").removeClass("selectColor");
                if ($(this).hasClass("allMajor")) {
                    // 如果是“全部”，单独处理
                    $(this).parent("li").addClass("selectColor");
                    if (vm.orgId != 0) {
                        // 获取全部的教师列表
                        vm.listTeacher(0, 1);
                    }
                    vm.orgId = 0;
                } else {
                    $(this).addClass("selectColor");
                }
            })
            
			// 打开课程管理页面
			function open_courseManager(obj) {
				var teacherNo = $(obj).attr("data-teacherNo");
				var teacherName = $(obj).attr("data-teacherName");
				var orgId = $(obj).attr("data-orgId");
				x_admin_show('课程管理【'+ teacherName +'】','/sys/teacher/course/toCourseManager?teacherNo=' + teacherNo + '&orgId=' + orgId,600,430);
			}
			
			// 打开课表安排页面
			function open_courseTime(obj) {
				var teacherNo = $(obj).attr("data-teacherNo");
                var teacherName = $(obj).attr("data-teacherName");
				x_admin_show('课表【'+ teacherName +'】','/sys/teacher/course/toCourseTime?teacherNo=' + teacherNo, 600, 430);
			}
			
			// 点击页码数，进行跳转
            $(".page").delegate(".num", "click", function() {
                var pageNum = $(this).attr("data");
                vm.listTeacher(vm.orgId, pageNum);
            });
            // 上一页
            $(".page").delegate(".prev", "click", function() {
                if (vm.pageInfo.hasPreviousPage) {
                    vm.listTeacher(vm.orgId, vm.pageInfo.pageNum - 1);
                }
            });
            // 下一页
            $(".page").delegate(".next", "click", function() {
                if (vm.pageInfo.hasNextPage) {
                    vm.listTeacher(vm.orgId, vm.pageInfo.pageNum + 1);
                }
            });
            // 首页
            $(".page").delegate(".first", "click", function() {
                if (!vm.pageInfo.isFirstPage) {
                    vm.listTeacher(vm.orgId, 1);
                }
            });
            // 尾页
            $(".page").delegate(".last", "click", function() {
                if (!vm.pageInfo.isLastPage) {
                    vm.listTeacher(vm.orgId, vm.pageInfo.pages);
                }
            });
		</script>
	</body>

</html>
